39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
75#define BRUSHLESS28_REG_IC_STAT1 0x00
76#define BRUSHLESS28_REG_IC_STAT2 0x01
77#define BRUSHLESS28_REG_IC_STAT3 0x02
78#define BRUSHLESS28_REG_IC_STAT4 0x03
79#define BRUSHLESS28_REG_IC_STAT5 0x04
80#define BRUSHLESS28_REG_IC_STAT6 0x05
81#define BRUSHLESS28_REG_IC_CTRL1 0x1A
82#define BRUSHLESS28_REG_IC_CTRL2 0x1B
83#define BRUSHLESS28_REG_IC_CTRL3 0x1C
84#define BRUSHLESS28_REG_GD_CTRL1 0x1E
85#define BRUSHLESS28_REG_GD_CTRL2 0x1F
86#define BRUSHLESS28_REG_GD_CTRL3 0x21
87#define BRUSHLESS28_REG_GD_CTRL3B 0x22
88#define BRUSHLESS28_REG_GD_CTRL4 0x23
89#define BRUSHLESS28_REG_GD_CTRL5 0x24
90#define BRUSHLESS28_REG_GD_CTRL6 0x25
91#define BRUSHLESS28_REG_GD_CTRL7 0x26
92#define BRUSHLESS28_REG_CSA_CTRL 0x29
93#define BRUSHLESS28_REG_MON_CTRL1 0x2B
94#define BRUSHLESS28_REG_MON_CTRL2 0x2C
95#define BRUSHLESS28_REG_MON_CTRL3 0x2D
96#define BRUSHLESS28_REG_MON_CTRL4 0x2E
97#define BRUSHLESS28_REG_SPI_TEST 0x36
98#define BRUSHLESS28_REG_OTP_USR 0x48
116#define BRUSHLESS28_IC_CTRL2_ENABLE_DRV 0x8000
117#define BRUSHLESS28_IC_CTRL2_MODE_NSLEEP 0x4000
118#define BRUSHLESS28_IC_CTRL2_CFG_CRC_EN 0x2000
119#define BRUSHLESS28_IC_CTRL2_CLKMON_EN 0x1000
120#define BRUSHLESS28_IC_CTRL2_CSA_EN 0x0800
121#define BRUSHLESS28_IC_CTRL2_CSA_AZ_DIS 0x0400
122#define BRUSHLESS28_IC_CTRL2_GVDD_MODE_LDO 0x0100
123#define BRUSHLESS28_IC_CTRL2_VCP_MODE_NORMAL 0x0000
124#define BRUSHLESS28_IC_CTRL2_VCP_MODE_SW_DIS 0x0040
125#define BRUSHLESS28_IC_CTRL2_VCP_MODE_SHUTDOWN 0x0080
126#define BRUSHLESS28_IC_CTRL2_VCP_MODE_TCP_DIS 0x00C0
127#define BRUSHLESS28_IC_CTRL2_VCP_MODE_MASK 0x00C0
128#define BRUSHLESS28_IC_CTRL2_LOCK_UNLOCK 0x0006
129#define BRUSHLESS28_IC_CTRL2_LOCK_LOCK 0x000C
130#define BRUSHLESS28_IC_CTRL2_LOCK_MASK 0x000E
131#define BRUSHLESS28_IC_CTRL2_CLR_FLT 0x0001
137#define BRUSHLESS28_GD_CTRL1_PWM_MODE_6X_PWM 0x0000
138#define BRUSHLESS28_GD_CTRL1_PWM_MODE_3X_PWM_INLX 0x1000
139#define BRUSHLESS28_GD_CTRL1_PWM_MODE_3X_PWM_SPI 0x2000
140#define BRUSHLESS28_GD_CTRL1_PWM_MODE_1X_PWM 0x3000
141#define BRUSHLESS28_GD_CTRL1_PWM_MODE_SPI_GATE 0x5000
142#define BRUSHLESS28_GD_CTRL1_PWM_MODE_MASK 0x7000
143#define BRUSHLESS28_GD_CTRL1_SGD_MODE_FIXED 0x0000
144#define BRUSHLESS28_GD_CTRL1_SGD_MODE_DYNAMIC 0x0200
145#define BRUSHLESS28_GD_CTRL1_SGD_MODE_MASK 0x0600
146#define BRUSHLESS28_GD_CTRL1_SGD_TMP_EN 0x0100
147#define BRUSHLESS28_GD_CTRL1_STP_MODE_0 0x0000
148#define BRUSHLESS28_GD_CTRL1_STP_MODE_1 0x0080
149#define BRUSHLESS28_GD_CTRL1_STP_MODE_MASK 0x0080
150#define BRUSHLESS28_GD_CTRL1_DEADT_70NS 0x0000
151#define BRUSHLESS28_GD_CTRL1_DEADT_200NS 0x0008
152#define BRUSHLESS28_GD_CTRL1_DEADT_300NS 0x0010
153#define BRUSHLESS28_GD_CTRL1_DEADT_500NS 0x0018
154#define BRUSHLESS28_GD_CTRL1_DEADT_750NS 0x0020
155#define BRUSHLESS28_GD_CTRL1_DEADT_1000NS 0x0028
156#define BRUSHLESS28_GD_CTRL1_DEADT_1500NS 0x0030
157#define BRUSHLESS28_GD_CTRL1_DEADT_2000NS 0x0038
158#define BRUSHLESS28_GD_CTRL1_DEADT_MASK 0x0038
159#define BRUSHLESS28_GD_CTRL1_DEADT_MODE_0 0x0000
160#define BRUSHLESS28_GD_CTRL1_DEADT_MODE_1 0x0004
161#define BRUSHLESS28_GD_CTRL1_DEADT_MODE_MASK 0x0004
162#define BRUSHLESS28_GD_CTRL1_DEADT_MODE_6X_0 0x0000
163#define BRUSHLESS28_GD_CTRL1_DEADT_MODE_6X_1 0x0001
164#define BRUSHLESS28_GD_CTRL1_DEADT_MODE_6X_2 0x0002
165#define BRUSHLESS28_GD_CTRL1_DEADT_MODE_6X_3 0x0003
166#define BRUSHLESS28_GD_CTRL1_DEADT_MODE_6X_MASK 0x0003
172#define BRUSHLESS28_SPI_TEST_WORD 0x5AA5
178#define BRUSHLESS28_SPI_FRAME_READ_BIT 0x01
179#define BRUSHLESS28_SPI_FRAME_CRC_DISABLE 0x00
180#define BRUSHLESS28_SPI_FRAME_CRC_ENABLE 0x01
181#define BRUSHLESS28_SPI_FRAME_CRC_MASK 0x01
187#define BRUSHLESS28_DIR_CW 0
188#define BRUSHLESS28_DIR_CCW 1
194#define BRUSHLESS28_DEF_DUTY 0.0
195#define BRUSHLESS28_DEF_FREQ 5000
205#define BRUSHLESS28_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
206#define BRUSHLESS28_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
224#define BRUSHLESS28_MAP_MIKROBUS( cfg, mikrobus ) \
225 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
226 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
227 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
228 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
229 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
230 cfg.brake = MIKROBUS( mikrobus, MIKROBUS_RST ); \
231 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
232 cfg.fault = MIKROBUS( mikrobus, MIKROBUS_INT )
brushless28_return_value_t
Brushless 28 Click return value data.
Definition brushless28.h:292
@ BRUSHLESS28_ERROR
Definition brushless28.h:294
@ BRUSHLESS28_OK
Definition brushless28.h:293
err_t brushless28_set_duty_cycle(brushless28_t *ctx, float duty_cycle)
Brushless 28 sets PWM duty cycle.
err_t brushless28_write_reg(brushless28_t *ctx, uint8_t reg, uint16_t data_in)
Brushless 28 data writing function.
err_t brushless28_default_cfg(brushless28_t *ctx)
Brushless 28 default configuration function.
void brushless28_cfg_setup(brushless28_cfg_t *cfg)
Brushless 28 configuration object setup function.
err_t brushless28_pwm_start(brushless28_t *ctx)
Brushless 28 start PWM module.
err_t brushless28_read_reg(brushless28_t *ctx, uint8_t reg, uint16_t *data_out)
Brushless 28 data reading function.
uint8_t brushless28_get_fault_pin(brushless28_t *ctx)
Brushless 28 get fault pin function.
void brushless28_set_direction(brushless28_t *ctx, uint8_t dir)
Brushless 28 set direction function.
void brushless28_pull_brake(brushless28_t *ctx)
Brushless 28 pull brake function.
err_t brushless28_init(brushless28_t *ctx, brushless28_cfg_t *cfg)
Brushless 28 initialization function.
err_t brushless28_pwm_stop(brushless28_t *ctx)
Brushless 28 stop PWM module.
void brushless28_switch_direction(brushless28_t *ctx)
Brushless 28 switch direction function.
void brushless28_release_brake(brushless28_t *ctx)
Brushless 28 release brake function.
This file contains SPI specific macros, functions, etc.
Brushless 28 Click configuration object.
Definition brushless28.h:266
spi_master_chip_select_polarity_t cs_polarity
Definition brushless28.h:282
pin_name_t sck
Definition brushless28.h:270
pin_name_t brake
Definition brushless28.h:276
spi_master_mode_t spi_mode
Definition brushless28.h:281
pin_name_t mosi
Definition brushless28.h:269
uint32_t spi_speed
Definition brushless28.h:280
uint32_t dev_pwm_freq
Definition brushless28.h:283
pin_name_t dir
Definition brushless28.h:275
pin_name_t pwm
Definition brushless28.h:272
pin_name_t miso
Definition brushless28.h:268
pin_name_t cs
Definition brushless28.h:271
pin_name_t fault
Definition brushless28.h:277
Brushless 28 Click context object.
Definition brushless28.h:242
uint8_t crc_en
Definition brushless28.h:257
spi_master_t spi
Definition brushless28.h:251
uint32_t pwm_freq
Definition brushless28.h:255
digital_out_t brake
Definition brushless28.h:245
digital_in_t fault
Definition brushless28.h:248
pin_name_t chip_select
Definition brushless28.h:254
pwm_t pwm
Definition brushless28.h:252
digital_out_t dir
Definition brushless28.h:244